package com.webchat.user.repository.dao;

import com.webchat.user.repository.entity.AccountRelationEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IAccountRelationDAO extends
        JpaSpecificationExecutor<AccountRelationEntity>,
        JpaRepository<AccountRelationEntity, Long> {


    AccountRelationEntity findAllBySourceAccountAndTargetAccount(String sourceAccount, String targetAccount);


    @Query(nativeQuery = true,
           value = "select * from " +
                   "web_chat_account_relation " +
                   "where " +
                   "type = :type " +
                   "and status = :status " +
                   "and (source_account = :account or target_account = :account)")
    List<AccountRelationEntity> getAccountRelations(String account, Integer type, Integer status);

}
